﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Negocio.Auxiliar;
using Negocio.Evento;

namespace Finalcountdown.Site.Consulta
{
    public partial class consultaApresentacao : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                carregarGrid();
            }
        }

        private void carregarGrid()
        {
            var obNEvento = new NEvento();
            var obListEventos = obNEvento.pegarEventos("", "", 1);

            grdResEvento.DataSource = obListEventos;
            grdResEvento.DataBind();
        }

        protected void grdResEvento_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "acompanhar":
                    var idEventoAcompanhar = e.CommandArgument.ToString();
                    Response.Redirect("~/Site/Acompanhar/acompanharEvento.aspx?id=" + idEventoAcompanhar);
                    break;
            }
        }

        protected void grdResEvento_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                var obNStatus = new NStatus();
                obNStatus.pegarStatusPorId(Convert.ToInt32(e.Row.Cells[3].Text));

                if (e.Row.Cells[3].Text == "2")
                {
                    var lkbAcompanhar = (LinkButton)e.Row.FindControl("lkbAcompanhar");
                    lkbAcompanhar.Enabled = false;

                }

                e.Row.Cells[3].Text = obNStatus.dsStatus;

                e.Row.Cells[2].Text = Convert.ToDateTime(e.Row.Cells[2].Text).ToShortDateString();

            }
        }
    }
}